<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>localStorage</title>
</head>
<body>
<h2>localStorage</h2>
<button onclick="saveData()">点我保存数据</button>
<button onclick="readData()">点我读取数据</button>
<button onclick="deleteData()">点我删除数据</button>
<button onclick="deleteAllData()">点我删除全部数据</button>
<script>
    let p = {name:"张三",age:18}
    function saveData(){
        window.localStorage.setItem('msg','hello!');
        window.localStorage.setItem('msg2',666);
        window.localStorage.setItem('person',JSON.stringify(p));
    }
    function readData(){
        console.log(window.localStorage.getItem('msg2'));
        console.log(window.localStorage.getItem('msg'));
        let result = window.localStorage.getItem('person');
        console.log(JSON.parse(result));

    }
    function deleteData(){
        window.localStorage.removeItem('msg2');
    }
    function deleteAllData(){
        window.localStorage.clear();
    }

</script>
</body>
</html>